<template>
  <div class="tooltip-wrap">
    <el-tooltip
      class="item"
      effect="dark"
      :content="content"
      :placement="placement"
      :disabled="disabled"
    >
      <p
        :class="[rows > 1 ? 'more-rows' : 'text-tips']"
        :style="{ '-webkit-line-clamp': rows }"
        @mouseenter="mouseenter"
        @mouseleave="mouseleave"
      >
        {{ content }}
      </p>
    </el-tooltip>
  </div>
</template>

<script>
export default {
  name: 'TextTooltip',
  props: {
    content: {
      type: String,
      default: '内容'
    },
    /**
     * @description: 设置超出隐藏的行数
     * @param {Number}
     */
    rows: {
      type: Number,
      default: 1
    },
    placement: {
      type: String,
      default: 'top'
    }
  },
  data() {
    return {
      disabled: true
    }
  },
  methods: {
    mouseenter(e) {
      //   console.log(e.target.clientWidth, e.target.scrollWidth)
      console.log(e.target.clientHeight, e.target.scrollHeight)
      if (this.rows > 1) {
        if (e.target.scrollHeight <= e.target.clientHeight) {
          this.disabled = true
        } else {
          this.disabled = false
        }
        return
      }
      if (e.target.scrollWidth <= e.target.clientWidth) {
        this.disabled = true
      } else {
        this.disabled = false
      }
      console.log(this.disabled)
    },
    mouseleave() {}
  }
}
</script>
<style lang="less" scoped>
.tooltip-wrap {
  p {
    margin: 0;
  }
  .text-tips {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .more-rows {
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-all;
  }
}
</style>
